const app = getApp();
const db = wx.cloud.database()
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    deviceslist: {},
    deviceid: '',
  },
  onLoad: function(options) {
    db.collection('device').get().then(res => {
      this.setData({ deviceslist: res.data })
    })
  },
  bindKeyInput: function (event) {
    this.setData({
      deviceid: event.detail.value
    })

  },
  deviceSearch:function(event){
    var deviceid=this.data.deviceid
    if (deviceid != '') {
      db.collection('device').where({
        deviceid: deviceid
      }).get().then(res => {
        this.setData({ deviceslist: res.data })
      })
    }
    else
    {
      db.collection('device').get().then(res => {
        this.setData({ deviceslist: res.data })
      })
    }
  },
  recordEdit:function(event)
  {
    wx.navigateTo({
      url: '../edit/edit?_id=' + event.currentTarget.dataset.id
    })
  },
})